/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Phan1.LietKe.QuayLui;

/**
 *
 * @author Giaotk
 */
public class ChinhHopChapK {
    int n,k;
    int[]x = new int[100];
    boolean []c = new boolean[100];
    StringBuilder result = new StringBuilder();
    
    public ChinhHopChapK(int n,int k){
        this.n=n;
        this.k=k;
        for (int i = 0; i < 100; i++) {
            c[i]=true;
        }
        Process(1);
        System.out.println(result);
    }
    
    public void Process(int i){
        for (int j = 1; j <= n; j++) {
            if (c[j]) {
                x[i] = j;
                if (i==k) {
                    PrintResult();
                }else{
                    c[j]=false;
                    Process(i+1);
                    c[j]=true;
                }
            }
        }
    }
    
    public void PrintResult(){
        for (int i = 1; i <= k; i++) {
            result.append(x[i]);
        }
        result.append("\n");
    }
    
}
